package Handler;

import Service.IProductService;
import Service.impl.ProductServiceImpl;
import pojo.Product;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class ProductHandler {
    public void showProductAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        IProductService productService=new ProductServiceImpl();
        List<Product> productList=productService.findAll();
        System.out.println(productList.size());
        request.setAttribute("productList",productList);
        request.getRequestDispatcher("/product/productList.jsp").forward(request,response);
    }
    public void showprodetails(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        IProductService productService=new ProductServiceImpl();
        int productid = Integer.parseInt(req.getParameter("productid"));
        Product product = productService.findById(productid);
        req.setAttribute("product1", product);
        req.getRequestDispatcher("/product/productDetail.jsp").forward(req, resp);
    }

}
